package com.study.d012Components.dialog;

import java.util.Optional;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.layout.AnchorPane;

/** Dialog弹出框
*@description
*@author xtayhame
*date 2020年3月14日
*version
*since v1.0
*/
public class DialogMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	public void start(javafx.stage.Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();

		Button button  = new Button("弹窗");

		anchorPane.getChildren().add(button);
		AnchorPane.setTopAnchor(button, 30.0);
		AnchorPane.setLeftAnchor(button, 30.0);

		stage.setScene(new Scene(anchorPane,400,300));
		stage.show();


		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {

				Dialog<ButtonType> dialog01 = new Dialog<ButtonType>();
				dialog01.getDialogPane().getButtonTypes().add(ButtonType.OK);
				dialog01.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
				dialog01.setContentText("ContentText");
				dialog01.setTitle("标题");
				dialog01.setHeaderText("HeaderText");
				dialog01.setGraphic(new Button("Graphic"));
				//这样设置没用
				//dialog01.setHeight(500);


				dialog01.show();

				Button okBtn = (Button)(dialog01.getDialogPane().lookupButton(ButtonType.OK));
				Button cancelBtn = (Button)(dialog01.getDialogPane().lookupButton(ButtonType.CLOSE));

				/*Optional<ButtonType> optional=dialog01.showAndWait();
				if(optional.isPresent() && optional.get()==ButtonType.OK){
					dialog01.setTitle("等待中...");
					System.out.println("===========");
				}*/


				okBtn.setOnAction(new EventHandler<ActionEvent>() {
					@Override
					public void handle(ActionEvent event) {
						System.out.println("点击OK.");


					}
				});

				cancelBtn.setOnAction(new EventHandler<ActionEvent>() {
					@Override
					public void handle(ActionEvent event) {
						System.out.println("点击Cancel.");

					}
				});





			}
		});
	};
}
